package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gemme.gemme.R;

public class InterestView extends RelativeLayout {
    private Context context;
    private OnSelectChange onSelectChange;

    public InterestView(Context context) {
        this(context,null);
    }

    public InterestView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public InterestView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    TextView tv;
    ImageView iv;
    boolean isSelect = false;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.item_interest,this);

        tv = findViewById(R.id.tv);
        iv = findViewById(R.id.iv);
        changeState();
        tv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                isSelect = !isSelect;
                changeState();
                if (onSelectChange != null)
                    onSelectChange.onSelectChange();
            }
        });
    }

    public InterestView setContent(String content){
        tv.setText(content);
        return this;
    }

    public String getContent(){
        return tv.getText() + "";
    }
    public boolean getSelect(){
        return isSelect;
    }

    public void changeState(){
        if(isSelect){
            iv.setBackgroundResource(R.drawable.select);
        }else{
            iv.setBackgroundResource(R.drawable.unselect);
        }
    }

    public void setOnSelectChange(OnSelectChange onSelectChange){

        this.onSelectChange = onSelectChange;
    }

    public interface OnSelectChange{
        void onSelectChange();
    }
}
